package com.sgb.kjwl.view.ui.activity.enterprise;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityIntellPropBinding;
import com.sgb.kjwl.di.enterprise.DaggerEnterpriseComponent;
import com.sgb.kjwl.di.enterprise.EnterpriseModule;
import com.sgb.kjwl.model.entity.lease.AskLeaseItemEntity;
import com.sgb.kjwl.view.ui.fragment.enterprise.IntellpropFragment;
import com.sgb.kjwl.viewmodel.enterprise.IntellPropModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 知识产权
 */
public class IntellPropAcitivity extends AppActivity {
    @Inject
    IntellPropModel viewModel;

    private ActivityIntellPropBinding binding;

    private ArrayList<Fragment> mFragments;
    private String[] titles = {"商标", "版权", "专利"};
    private int position;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerEnterpriseComponent.builder().appComponent(appComponent)
                .enterpriseModule(new EnterpriseModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, IntellPropAcitivity.class);
        context.startActivity(intent);
    }

    public static void start(Context context, int position) {
        Intent intent = new Intent();
        intent.putExtra("position", position);
        intent.setClass(context, IntellPropAcitivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_intell_prop);
        position = getIntent().getIntExtra("position", 0);
        binding.include.ivBack.setVisibility(View.VISIBLE);
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.include.titleView.setText("知识产权");

    }

    @Override
    protected void init() {
        mFragments = new ArrayList<>();
        showTypeView();
    }


    public void showTypeView() {

        for (int i = 0; i < titles.length; i++) {
            mFragments.add(IntellpropFragment.newInstance(i, ""));

        }
        SlidingFragmentPagerAdapter pagerAdapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        binding.viewpager.setCurrentItem(position);

        binding.viewpager.setOffscreenPageLimit(titles.length);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.tablayout.setupWithViewPager(binding.viewpager);
    }

    public void changeType(int position) {
        binding.viewpager.setCurrentItem(position);
    }

}
